# pop from last item or specific item
def pop_demo():
    list1 = [1, 2, 3, 4, 5, 6]

    print(list1.pop())  # 6

    print(f'list after pop:{list1}')  # [ 1,2,3,4,5]

    list2 = [1, 2, 3, ('cat', 'bat'), 4]

    print(list2.pop(2))  # 3
    print(list2.pop())  # 4
    print(list2.pop())  # ('cat', 'bat')

    print(f"after pop:{list2}")


def extent_list(value, List=[]):
    print(f"list:{List}")
    List.append(value)
    return List


def extent_demo():
    # only second arg(List) is miss,is the same invoke
    list1 = extent_list(11)  # []
    list2 = extent_list(12, [])  # []
    list3 = extent_list(13, [])  # []
    list4 = extent_list("a")  # [11]
    list5 = extent_list(15, [3])  # [3]
    list6 = extent_list(16, [4])  # [4]
    list7 = extent_list("b")  # [11,"a"]

    # [11, 'a', 'b'],[12],[13],[11, 'a', 'b'],[3, 15],[4, 16],[11, 'a', 'b']
    print(f"{list1},{list2},{list3},{list4},{list5},{list6},{list7}")


def common_demo():
    x = [1, 2]  # [1, 2]
    print(x)
    x.append([3, 4])  # [1, 2, [3, 4]]
    print(x)
    x.extend([5, 6])  # [1, 2, [3, 4], 5, 6]
    print(x)
    x[0] = 7  # [7, 2, [3, 4], 5, 6]
    print(x)
    x.insert(0, 8)  # [8, 7, 2, [3, 4], 5, 6]
    print(x)
    del x[1]  # [8, 2, [3, 4], 5, 6]
    print(x)
    x.append(2)  # [8, 2, [3, 4], 5, 6, 2]
    print(x)
    x.remove(2)  # [8, [3, 4], 5, 6, 2] # 删除的事第一个 2
    print(x)
    x.pop(3)  # 删除索引为 3 的项，就是6
    print(x)  # [8, [3, 4], 5, 2]


if __name__ == '__main__':
    common_demo()
    pop_demo()
    extent_demo()
